/*
题目连接:https://leetcode.cn/problems/count-subarrays-with-score-less-than-k/description/?envType=daily-question&envId=2025-04-28
*/

//题解代码:
class Solution {
public:
    #define ll long long
    long long countSubarrays(vector<int>& nums, long long k) {
        ll ans = 0;
        int n =  nums.size();
        vector<ll> presum(n+1,0);
        for(int i=0;i<n;++i){
            presum[i+1] = presum[i] + nums[i];
        }
        for(int l=0,r=0;r<n;++r){
            while((presum[r+1]-presum[l]) * (r-l+1) >= k){
                ++l;
            }
            ans += r-l+1;
        }
        return ans;
    }
};
